<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台主页模块 - XzcBlogTemplate后台管理</title>
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/common.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/blogadd.css">

</head>
<body>
<div class="layui-container main">
    <div class="layui-row layui-col-space20">
        <div class="layui-col-md12">
            <p>
		        	<span class="layui-breadcrumb" style="visibility: visible;">
			          	<a >博客管理系统</a><span lay-separator="">/</span>
			          	<a >后台首页</a><span lay-separator="">/</span>
			          	<a><cite>文章管理</cite></a>
		        	</span>
            </p>
        </div>
        <div class="layui-col-md12">
            <table class="layui-table">
                <colgroup>
                    <col width="200">
                    <col width="400">
                    <col>
                </colgroup>
                <thead>
                <tr>
                    <th>标题</th>
                    <th>内容简介</th>
                    <th>分类</th>
                    <th>标签</th>
                    <th>点击量</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                </tbody>

            </table>
            <div class="layui-col-md12 margin20" id="pages"></div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="static/js/jquery-1.12.4.min.js"></script>
<script src="static/layui/layui.all.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
        $.get("Blog/showText", {"page": 1}, function (rs) {
            var Text = rs.result;
            if (localStorage.getItem("identity") == 1) {
                for (var i = 0; i < Text.length; i++) {
                    $("<tr>\n" +
                        "<td >" + Text[i].title + "</td>" +
                        "<td >" + Text[i].detail.substring(0, 50) + "</td>" +
                        "<td >" + Text[i].type + "</td>" +
                        "<td >" + Text[i].type + "</td>" +
                        "<td>" + Text[i].clicknumber + "</td>" +
                        "<td>" + Text[i].posttime + "</td>" +
                        "<td>" +
                        "<a  class=\"layui-btn layui-btn-normal\" title='编辑' name='" + Text[i].blogid + "'>编辑</a>" +
                        "<input type=\"button\" id=\"del_btn\"  class=\"layui-btn layui-btn-danger\" value=\"删除\" name='" + Text[i].blogid + "'>" +
                        "</td>" +
                        "</tr>").appendTo("tbody");
                }
            } else if (localStorage.getItem("identity") == 0) {
                var uid = localStorage.getItem("uid");
                $.get("Us/quanxian", {"uid": uid, "page": 1}, function (ru) {
                    var ri = ru.result;
                    for (var i = 0; i < ri.length; i++) {
                        $("<tr>\n" +
                            "<td >" + ri[i].title + "</td>" +
                            "<td >" + ri[i].detail.substring(0, 50) + "</td>" +
                            "<td >" + ri[i].type + "</td>" +
                            "<td >" + ri[i].type + "</td>" +
                            "<td>" + ri[i].clicknumber + "</td>" +
                            "<td>" + ri[i].posttime + "</td>" +
                            "<td>" +
                            "<a  class=\"layui-btn layui-btn-normal\" title='编辑' name='" + ri[i].blogid + "'>编辑</a>" +
                            "<input type=\"button\" id=\"del_btn\"  class=\"layui-btn layui-btn-danger\" value=\"删除\" name='" + ri[i].blogid + "'>" +
                            "</td>" +
                            "</tr>").appendTo("tbody");
                    }
                });
            }
        });
        $(document).on("click", "a[title='编辑']", function () {
            var blogid = $(this).attr("name");
            sessionStorage.setItem("blogid", blogid);
            window.location.href = "http://localhost:8080/update.html";
        });
        /*给删除创建一个单击事件*/
        $(document).on("click", "input[type=\"button\"]", function () {
            /*发送异步请求*/
            var blogid = $(this).attr("name");
            /*通过删除方法，去删除信息*/
            $.get("Blog/deleteBackById", {"blogid": blogid}, function (rs) {
                /*转换成JSON格式*/
                alert(rs.result);
                window.location.href = "bloglist.html";
            });
        });
    });
</script>
<script>
    $(document).ready(function () {
        if (localStorage.getItem("identity") == 1) {
            $.get("Blog/count", function (count) {
                s = count;
                layui.carousel.render({
                    elem: '#carousel'
                    , width: '100%' //设置容器宽度
                    , arrow: 'always' //始终显示箭头
                    //,anim: 'updown' //切换动画方式
                });
                layui.laypage.render({
                    elem: 'pages', //注意，这里的 pages 是 ID，不用加 # 号
                    count: s, //数据总数，从服务端得到
                    limit: 5,   //每页条数设置
                    jump: function (obj, first) {
                        //obj包含了当前分页的所有参数，比如：
                        page = obj.curr;  //改变当前页码
                        limit = obj.limit;
                        //首次不执行
                        if (!first) {
                            $("tbody").empty();
                            var page = obj.curr;
                            $.get("Blog/showText", {"page": page}, function (rs) {
                                var Text = rs.result;
                                for (var i = 0; i < Text.length; i++) {

                                    $("<tr>\n" +
                                        "<td >" + Text[i].title + "</td>" +
                                        "<td >" + Text[i].detail.substring(0, 50) + "</td>" +
                                        "<td >" + Text[i].type + "</td>" +
                                        "<td >" + Text[i].type + "</td>" +
                                        "<td>" + Text[i].clicknumber + "</td>" +
                                        "<td>" + Text[i].posttime + "</td>" +
                                        "<td>" +
                                        "<a  class=\"layui-btn layui-btn-normal\" title='编辑' name='" + Text[i].blogid + "'>编辑</a>" +
                                        "<input type=\"button\" id=\"del_btn\"  class=\"layui-btn layui-btn-danger\" value=\"删除\" name='" + Text[i].blogid + "'>" +
                                        "</td>" +
                                        "</tr>").appendTo("tbody");
                                }
                            });
                        }
                    }
                });
            });
        } else if (localStorage.getItem("identity") == 0) {
            var uid = localStorage.getItem("uid");
            $.get("Blog/count", {"uid": uid}, function (count) {
                s = count;
                layui.carousel.render({
                    elem: '#carousel'
                    , width: '100%' //设置容器宽度
                    , arrow: 'always' //始终显示箭头
                });
                layui.laypage.render({
                    elem: 'pages', //注意，这里的 pages 是 ID，不用加 # 号
                    count: s, //数据总数，从服务端得到
                    limit: 5,   //每页条数设置
                    jump: function (obj, first) {
                        //obj包含了当前分页的所有参数，比如：
                        page = obj.curr;  //改变当前页码
                        limit = obj.limit;
                        //首次不执行
                        if (!first) {
                            $("tbody").empty();
                            var page = obj.curr;
                            var uid = localStorage.getItem("uid");
                            $.get("Us/quanxian", {"page": page, "uid": uid}, function (ru) {
                                var ri = ru.result;
                                for (var i = 0; i < ri.length; i++) {
                                    $("<tr>\n" +
                                        "<td >" + ri[i].title + "</td>" +
                                        "<td >" + ri[i].detail.substring(0, 50) + "</td>" +
                                        "<td >" + ri[i].type + "</td>" +
                                        "<td >" + ri[i].type + "</td>" +
                                        "<td>" + ri[i].clicknumber + "</td>" +
                                        "<td>" + ri[i].posttime + "</td>" +
                                        "<td>" +
                                        "<a  class=\"layui-btn layui-btn-normal\" title='编辑' name='" + ri[i].blogid + "'>编辑</a>" +
                                        "<input type=\"button\" id=\"del_btn\"  class=\"layui-btn layui-btn-danger\" value='删除' name='" + ri[i].blogid + "'>" +
                                        "</td>" +
                                        "</tr>").appendTo("tbody");
                                }
                            });
                        }
                    }
                });
            });
        }
    });
</script>
</html>